package com.ruoyi.web.controller.wq;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wq.domain.WqQuestion;
import com.ruoyi.wq.domain.WqQuestionReply;
import com.ruoyi.wq.service.IWqQuestionReplyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.QuestionService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 回复提问Controller
 * 
 * @author ruoyi
 * @date 2024-04-04
 */
@RestController
@RequestMapping("/wq/questionReply")
public class WqQuestionReplyController extends BaseController {

    @Autowired
    private IWqQuestionReplyService wqQuestionReplyService;
    
    @Autowired
    private QuestionService questionService;
    
    /**
     * 回复提问
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WqQuestionReply wqQuestionReply){
        return AjaxResult.success(questionService.addReply(wqQuestionReply));
    }

    /**
     * 查询回复提问列表
     */
    @PreAuthorize("@ss.hasPermi('wq:reply:list')")
    @GetMapping("/list")
    public TableDataInfo list(WqQuestionReply wqQuestionReply)
    {
        startPage();
        List<WqQuestionReply> list = wqQuestionReplyService.selectWqQuestionReplyList(wqQuestionReply);
        return getDataTable(list);
    }

    /**
     * 导出回复提问列表
     */
    @PreAuthorize("@ss.hasPermi('wq:reply:export')")
    @Log(title = "回复提问", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WqQuestionReply wqQuestionReply)
    {
        List<WqQuestionReply> list = wqQuestionReplyService.selectWqQuestionReplyList(wqQuestionReply);
        ExcelUtil<WqQuestionReply> util = new ExcelUtil<WqQuestionReply>(WqQuestionReply.class);
        util.exportExcel(response, list, "回复提问数据");
    }

    /**
     * 获取回复提问详细信息
     */
    @PreAuthorize("@ss.hasPermi('wq:reply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(wqQuestionReplyService.selectWqQuestionReplyById(id));
    }

    /**
     * 修改回复提问
     */
    @PreAuthorize("@ss.hasPermi('wq:reply:edit')")
    @Log(title = "回复提问", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WqQuestionReply wqQuestionReply)
    {
        return toAjax(wqQuestionReplyService.updateWqQuestionReply(wqQuestionReply));
    }

    /**
     * 删除回复提问
     */
    @PreAuthorize("@ss.hasPermi('wq:reply:remove')")
    @Log(title = "回复提问", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(wqQuestionReplyService.deleteWqQuestionReplyByIds(ids));
    }
}
